<template>
	<view>
		<view class="serwch">
			<my-cearch @goSearch="goSearch" ></my-cearch>
		</view>
	<view class="xaingqing">
		
		<!-- 左侧导航栏 -->
		<scroll-view :style="{height:wh,width:ww}" class="left_box" scroll-y='true'>
			<view class="scroll_box "
			 
			 @click="dianji(index)"
			 :class="{active:navi ==index}" v-for="(item,index) in cateList"
			  :key="index">
				{{item.cat_name}}
			</view>
			
		</scroll-view>
		
		<!-- 右侧的滚动视图区域 -->
		<scroll-view class="right-scroll-view" :scroll-top='scrolltop' scroll-y='true':style="{height: wh }">
		  <view class="cate-lv2" v-for="(item2, i2) in cateLevel2" :key="i2">
		    <view class="cate-lv2-title">/ {{item2.cat_name}} /</view>
			<view class="cate-lv3-list" @click="jumpDatails(item2)">
			      <!-- 三级分类 Item 项 -->
			      <view class="cate-lv3-item" v-for="(item3, i3) in item2.children" :key="i3">
			        <!-- 图片 -->
					
			        <image :src="item3.cat_icon"></image>
			        <!-- 文本 -->
			        <text>{{item3.cat_name}}</text>
			      </view>
			    </view>
			
		  </view>
		</scroll-view>
	</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/index.js'
	
	export default {
		
		mixins:[badgeMix],
		data() {
			return {
				wh:null,
				ww:'100px',
				// 分类数据列表
				    cateList: [],
					// 二级分类列表
					    cateLevel2: [],
					// 导航栏点击控制
					navi:0,
					scrolltop:100
			};
		},
		
		onLoad(){
			
			const data= uni.getSystemInfoSync()
			this.wh=data.windowHeight +'px'
			console.log(this.wh);
			
			this.getCateList()
			
			this.getCateLevel()
		},
		
		methods:{
			
			
			// 获取左侧导航栏数据
			async getCateList(){
				
				const {data} = await uni.$http.get('/api/public/v1/categories')
				
				this.cateList=data.message
				// console.log(this.cateList);
				
			},
			
			// 获取右侧导航栏数据
			async getCateLevel(){
				const {data} =await uni.$http.get('/api/public/v1/categories')
				this.cateLevel2=data.message
			  // 为二级分类赋值
			  this.cateLevel2 = data.message[0].children
			},
			
			// 跳转详情
			jumpDatails(item){
				
		
				uni.navigateTo({
					url:`/goods_list/goods_list/goods_list?cid=${item.cat_id}`
				});
				
			},
			
			// 搜索跳到详情
			goSearch(){
			
				uni.navigateTo({
					url:`/subpkg/se4arch/se4arch`
				});
			},
			// 点击导航栏换色
			dianji(index){
				this.navi=index
				
				this.scrolltop= this.scrolltop==0?1:0
				// 为二级分类列表重新赋值
				  this.cateLevel2 = this.cateList[index].children
			}
		}
	}
</script>

<style lang="scss">

.xaingqing{display: flex;}
.scroll_box{
	 line-height: 60px;
	      background-color: #f7f7f7;
	      text-align: center;
	      font-size: 12px;
		  
		     // 激活项的样式
		    
			
			   
			  
}

 .active {
		         background-color: #ffffff;
		         position: relative;
		 // 渲染激活项左侧的红色指示边线
		 &::before {
		   content: ' ';
		   display: block;
		   width: 3px;
		   height: 30px;
		   background-color: #c00000;
		   position: absolute;
		   left: 0;
		   top: 50%;
		   transform: translateY(-50%);
		 }
		      
		       }
			   .cate-lv2-title {
			     font-size: 12px;
			     font-weight: bold;
			     text-align: center;
			     padding: 15px 0;
			   }
.cate-lv3-list {
  display: flex;
  flex-wrap: wrap;

  .cate-lv3-item {
    width: 33.33%;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;

    image {
      width: 60px;
      height: 60px;
    }

    text {
      font-size: 12px;
    }
  }
}

.left_box{ ::v-deep ::-webkit-scrollbar {
			   		    display: none;
			   		    width: 0 !important;
			   		    height: 0 !important;
			   		    -webkit-appearance: none;
			   		    background: transparent;
			   		    color: transparent;
			   		  } }
 
 
 .serwch{
	 position: sticky;
	 
	 top: 0;
	 z-index: 9999;
 }
</style>
